import { ref } from "vue";
import { delay } from "@/utils";
import { detailApi } from "@/api/user.js";
export const useDetail = function (id) {
  const detailRef = ref(null);
  const activities = ref([]);
  detailApi(undefined, {
    id,
  }).then(async (resp) => {
    const { code, msg, data } = resp;
    await delay(1000);
    if (code === 200) {
      detailRef.value = data;
      const { state } = data;
      activities.value = [
        {
          content: "摘牌完成",
          size: "large",
          type: "primary",
        },
        {
          content: "已经交完保证金",
          type: state >= 2 ? "primary" : "info",
          hollow: true,
        },
        {
          content: "交易审核完成",
          type: state >= 3 ? "primary" : "info",
          hollow: true,
        },
        {
          content: "物流",
          type: state >= 4 ? "primary" : "info",
          hollow: true,
        },
        {
          content: "完成订单",
          type: state >= 5 ? "primary" : "info",
          hollow: true,
        },
      ];
    }
  });

  return {
    detail: detailRef,
    activities,
  };
};
